package cn.lili.common.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResponseBean {
    // 响应码
    private int code;

    // 相应描述
    private String msg;

    // 相应数据
    private Object data;

    //扩展字段，评价ID
    private Integer v_id;

    public static ResponseBean success = new ResponseBean(200, "成功", "");
    public static ResponseBean faild = new ResponseBean(500, "失败", "");

    public ResponseBean(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public ResponseBean(int code, String msg, Integer v_id) {
        this.code = code;
        this.msg = msg;
        this.v_id = v_id;
    }


    public static Map<String, Object> successMap(String key, Object data) {
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("code", 200);
        resultMap.put("msg", "成功");
        resultMap.put(key, data);
        return resultMap;
    }

    public static ResponseBean success(Object data) {
        return new ResponseBean(200, "成功", data);
    }

    public static ResponseBean success(String msg, Object data) {
        return new ResponseBean(200, msg, data);
    }

    public static ResponseBean faild(Object data) {
        return new ResponseBean(500, "失败", data);
    }

    public static ResponseBean faild(String msg, Object data) {
        return new ResponseBean(500, msg, data);
    }

}
